using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Shake.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Media.Imaging;
namespace MicroMsg.Plugin.Shake
{
	public class Shake : PluginBase, FMsgChange
	{
		private const string TAG = "Shake";
		public const string PluginKey = "Plugin Shake";
		public const long PluginID = 32771L;
		public const string PluginName = "Shake";
		public const int PluginVersion = 256;
		public const string bNotShowLbsTipKey = "bNotShowDialogInLbs";
		private static Shake mInstance;
		public ShakeService sceneShakeService;
		public override string mTitle
		{
			get
			{
				return Util.capitalString(strings.Shake_Title);
			}
		}
		public override string mFFEntryTitle
		{
			get
			{
				return Util.capitalString(strings.Shake_Title);
			}
		}
		public override BitmapSource mIcon
		{
			get
			{
				if (MMTheme.IsCoolBlackTheme())
				{
					return ImageCacheMgr.loadFromRes("Resource/Img/Plugin/Shake/plugin_setting_cool.png");
				}
				return ImageCacheMgr.loadFromRes("Resource/Img/Plugin/Shake/plugin_setting_normal.png");
			}
		}
		public override BitmapSource mIconHD
		{
			get
			{
				return ImageCacheMgr.loadFromRes("Resource/Img/Plugin/Shake/plugin_setting_HD.png");
			}
		}
		public override BitmapSource mIconInList
		{
			get
			{
				return this.mIcon;
			}
		}
		public override string mDescription
		{
			get
			{
				return strings.Shake_Description;
			}
		}
		public override string mAuthor
		{
			get
			{
				return "tencent";
			}
		}
		public Shake()
		{
			this.mKey = "Plugin Shake";
			this.mID = 32771L;
			this.mName = "Shake";
			this.mVersion = 256;
			this.mIndexInTab = MainTabIndex.FindFriendTab;
			this.mIndexInGroup = 0;
			this.mIndexInPosition = 0;
			this.mProtocolPluginFlag = EPluginFlag.MM_SHAKE_UNISTALL;
			this.mDefaultInstalled = true;
			Shake.mInstance = this;
			base.mIconInFFEntry = ImageCacheMgr.loadFromRes(MMTheme.GetInstance().shake_main);
		}
		public override PluginSettingBaseCtrl GetPluginSettingCtrl()
		{
			return new ShakePlguinSetCtrl();
		}
		private void onBtnClickShake(object sender, RoutedEventArgs e)
		{
			this.execute(4, null);
		}
		public static Shake getInstance()
		{
			return Shake.mInstance;
		}
		public override void onRegisterResult(RetConst retConst_0, int code)
		{
			Log.smethod_4("Shake", string.Concat(new object[]
			{
				"on register result , ret = ",
				retConst_0,
				", code = ",
				code
			}));
		}
		public override bool onInitialize()
		{
			Log.smethod_4("Shake", "initialize. ");
			this.refreshUnReadCnt();
			FMsgMgr.addObserver(this);
			this.sceneShakeService = new ShakeService();
			using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
			{
				string pluginPath = StorageIO.getPluginPath("Shake");
				if (!userStoreForApplication.DirectoryExists(pluginPath))
				{
					userStoreForApplication.CreateDirectory(pluginPath);
				}
			}
			return true;
		}
		public override bool onUnInitialize()
		{
			Log.smethod_4("Shake", "onUnInitialize");
			base.onUnInitialize();
			FMsgMgr.removeObserver(this);
			return true;
		}
		public override bool onInstalled(InstallMode mode)
		{
			Log.smethod_4("Shake", "on inistalled. ");
			this.refreshUnReadCnt();
			return true;
		}
		public override bool onUninstalled(InstallMode mode)
		{
			Log.smethod_4("Shake", "on uninstalled. ");
			this.sceneShakeService.clearAllContact();
			FMsgMgr.CleanByType(FMsgType.shake);
			return true;
		}
		public override bool onParseChatMsg(ChatMsg chatMsg)
		{
			return false;
		}
		public override object execute(int entryType, object args)
		{
			Log.smethod_4("Shake", "plugin execute,   entrytype =" + entryType);
			if (entryType == 1)
			{
				return null;
			}
			if (entryType == 2)
			{
				return null;
			}
			if (entryType == 3)
			{
				if (base.isInstalledPlugin())
				{
					this.EntryToShakePage();
				}
				else
				{
					ToolFunction.GotoPageForUserControl("/Source/Plugin/PluginSettingPage.xaml", new object[]
					{
						this
					}, false);
				}
				return null;
			}
			if (entryType == 4)
			{
				this.EntryToShakePage();
				return null;
			}
			return null;
		}
		private void EntryToShakePage()
		{
			object[] pData = new object[]
			{
				default(object),
				"/source/plugin/shake/ui/shakepage.xaml"
			};
			LocationServiceTipPage.GotoThisPage(pData);
		}
		public override void SetFFEntryCallBack(StandardUITaskDlg FFEntryCallBack)
		{
			this.mFFEntryCallBack = FFEntryCallBack;
			this.refreshUnReadCnt();
		}
		private void refreshUnReadCnt()
		{
			int newMsgNum = FMsgMgr.getNewMsgNum(FMsgType.shake);
			this.setUnreadCnt(newMsgNum);
		}
		private void setUnreadCnt(int nCnt)
		{
			if (this.mFFEntryCallBack != null)
			{
				try
				{
					this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_Cnt, nCnt);
				}
				catch
				{
				}
			}
		}
		public void onFMsgAdd(ChatMsg chatMsg_0, FMsgType type)
		{
			if (type == FMsgType.shake)
			{
				this.refreshUnReadCnt();
			}
		}
		public void onFMsgDel(ChatMsg chatMsg_0, FMsgType type)
		{
			if (type == FMsgType.shake)
			{
				this.refreshUnReadCnt();
			}
		}
		public void onFMsgNewNumChange(FMsgType type)
		{
			if (type == FMsgType.shake)
			{
				this.refreshUnReadCnt();
			}
		}
	}
}
